<?php 

/* Copyright 2010 John Hooley

	  
    This file is part of Portfolio Zen.



    Portfolio Zen is free software: you can redistribute it and/or modify

    it under the terms of the GNU General Public License as published by

    the Free Software Foundation, either version 3 of the License, or

    (at your option) any later version.



    Portfolio Zen is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    GNU General Public License for more details.



    You should have received a copy of the GNU General Public License

    along with Portfolio Zen.  If not, see <http://www.gnu.org/licenses/>.

 */ 



defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.model');

class PortfoliozenModelGalleries extends JModel {

  private $_galleries = array();

  public function getGalleries(){
    $this->_load();
    return $this->_galleries;
  }

  private function _load(){  
    $section = $this->_getSectionId();
    $galleries = $this->_query($section);
    foreach($galleries as $gallery){
      $this->_galleries[$gallery['id']] = $gallery['title'];
    }
  }

  private function _query($section){
    $db =& JFactory::getDBO();
    $sql = "SELECT " . $db->nameQuote('id') . "," . $db->nameQuote('title') . " FROM #__categories
           WHERE " . $db->nameQuote('section') . " = " . $db->quote($section) . " AND ".
           $db->nameQuote('published') . " = " . $db->quote('1') . " ORDER BY " . 
           $db->nameQuote('ordering') . " ASC";
    $db->setQuery($sql);
    return $db->loadAssocList();
  }

  private function _getSectionId(){
    global $option;
    $app =& JFactory::getApplication();
    $params =& $app->getParams($option);
    return $params->get('section');
  }

}